/***************************************************
> Copyright (C) 2024 ==KINGYI== All rights reserved.
> File Name: crc_test.c
> Author:cjy
> Mail: 
> Created Time: 2024年12月16日 星期一 16时58分35秒
***************************************************/

#include <stdio.h>
const unsigned char crc8_poly = 0x07;

unsigned char crc8(unsigned char * data,int size){
	unsigned char crc = 0;
	for (int i = 0;i < size;i++){
		crc ^= data[i];
		for (int j = 0;j < 8;j++){
			if(crc & 0x80){
				crc = (crc << 1)^crc8_poly;
			}else{
				crc <<= 1;
			}
		}
	}
	return crc;
}

int main(int argc,const char* argv[])
{
	unsigned char *data = "jaisueygtrfewfwe{}";
	
	int size = sizeof(data);

	unsigned char crc_value = crc8(data,size);

	printf ("crc-8校验值为:0x%02x\n",crc_value);

    return 0;
}
